/*
 * Copyright (c) 2006-2021, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2025-05-13     Administrator       the first version
 */
#ifndef HARDWARE_GYROSCOPE_H_
#define HARDWARE_GYROSCOPE_H_

#include "system.h"

#define Gyroscope_TASK_PRIO       12
#define Gyroscope_STK_SIZE        1024

#define SAMPLE_UART_NAME    "uart2"    // 根据实际设备修改
#define RX_BUFFER_SIZE      128        // 接收缓冲区大小

/* 欧拉角计算相关变量 */
// 串口接收状态标识
#define WAIT_HEADER1 0
#define WAIT_HEADER2 1
#define RECEIVE_DATA 2

//环形缓冲区
#define RX_RINGBUF_SIZE 256

void Gyroscope_task(void *parameter);

/*DMA中断回调接收函数*/
rt_err_t uart2_dma_callback(rt_device_t dev, rt_size_t size);

/*硬件接口初始化*/
int uart2_dma_init(void);

/*欧拉角计算*/
void process_euler_angles(void);

/* 阻塞发送单字节 */
void jy61p_send_byte(uint8_t data);

/* 发送零偏航角命令 */
void Serial_JY61P_Zero_Yaw(void);

/*数据处理线程*/
void JY61P_data_process_thread_entry(void);

extern float Pitch,Roll,Yaw;
// 定义接收变量
extern uint8_t RollL, RollH, PitchL, PitchH, YawL, YawH, VL, VH, SUM;
extern uint8_t receivedData[9];
//环形缓冲区
extern struct rt_ringbuffer gyro_rx_rb;
extern uint8_t gyro_rx_raw_buf[RX_RINGBUF_SIZE];  // 后台接收缓冲

#endif /* HARDWARE_GYROSCOPE_H_ */
